import { createStore } from 'vuex'

const accessToken = window.localStorage.getItem('accessToken')
const refreshToken = window.localStorage.getItem('refreshToken')

export default createStore({
  state: {
    accessToken: accessToken, // 请求token
    refreshToken: refreshToken, // 刷新token
    menuState: { // 系统菜单选中状态配置
      defaultOpeneds: [],
      defaultActive: ''
    },
    include: [], // router缓存配置
    asideH: '', // 系统菜单区域高度
    mainH: '', // 系统内容区域高度
    productId: '', // 商品id，商品新增，编辑时候使用
    dictData: {}   // 全局字典
  },
  mutations: {
    accessToken(state, data) {
      state.accessToken = data
    },
    refreshToken(state, data) {
      state.refreshToken = data
    },
    menuState(state, data) {
      state.menuState = data
    },
    include(state, data) {
      state.include = data
    },
    asideH(state, data) {
      state.asideH = data
    },
    mainH(state, data) {
      state.mainH = data
    },
    productId(state, data) {
      state.productId = data
    },
    dictData(state, data) {
      state.dictData = data
    }
  },
  getters: {
    getDictByKey(state) {
      return function(key) {
        return state.dictData[key]
      }
    }
  }
})

